﻿///----------------------------------------------------------------
/// Copyright (C) 2013-2014 正中科技
/// 版权所有。
///
/// 文件名：TB_XMK_FILEDAL.cs
/// 文件功能描述：Tb_Xmk_FileData数据访问类
///
///
/// 创建标识：黄永生 2014/3/23
///
/// 修改标识：
/// 修改描述：
///
/// 修改标识：
/// 修改描述：
///---------------------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using XMK.Tadong.Model;
using XMK.Framework.DataAccess;
using XMK.Utils;
using XMK.Tadong.Model.Cond;
namespace XMK.Tadong.Data
{
    public class Tb_Xmk_FileData
    {
        #region  构造函数

        /// <summary>
        /// 数据库连接
        /// </summary>
        protected DbProvider dbProvider;
        public Tb_Xmk_FileData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }

        #endregion  构造函数

        #region  成员方法
        /// <summary>
        /// 判断本用户下是否已有同名文件
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool IsExist(TB_XMK_FILEInfo fileObj)
        {
            string save_path = fileObj.SAVE_PATH;
            string name = fileObj.FILE_NAME;

            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT count(*) FROM TB_XMK_FILE WHERE SAVE_PATH = '" + save_path + "' and FILE_NAME='" + name + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd);

            return (Convert.ToInt16(obj) != 0);


        }

        /// <summary>
        /// 判断同一目录下是否有多个引用
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public bool HasSavePath(string Save_Path)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT count(*) FROM TB_XMK_FILE WHERE Save_Path = '" + Save_Path + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd);

            return (Convert.ToInt16(obj) > 1);


        }

        public bool IsMoreThanOne(string savePath, string fileName)
        {
            string save_path = savePath;
            string name = fileName;

            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT count(*) FROM TB_XMK_FILE WHERE SAVE_PATH = '" + save_path + "' and FILE_NAME='" + name + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd);

            return (Convert.ToInt16(obj) > 1);
        }




        /// <summary>
        /// 添加新文件
        /// </summary>
        /// <returns></returns>
        public bool InsertNewFile(TB_XMK_FILEInfo model)
        {
            bool result = true;
            string sql = @"insert into TB_XMK_FILE(TEAM_ID,    FILE_NAME,    FILE_EXT,   FILE_ABST,    FILE_AUTHOR,  KEYW,    FILE_CRT_DATE,  FILE_VERSION,FILE_SIZE，DOWN_AMOUNT，  DEST_OBJ,  BIZ_OBJ    ,SECRET_LVL   ,LANG_TYPE,    FILE_TYPE,    SAVE_PATH,   USER_ID,  STATUS,    CREATE_TIME,   UPD_TIME,FOLDER_ID,TEAM_NAME,FORM_UNIT,SHARED_SCOPE_ID,PDF_PATH,SWF_PATH) 
					                        VALUES(:p_TEAM_ID,:p_FILE_NAME,:p_FILE_EXT,:p_FILE_ABST,:p_FILE_AUTHOR,:p_KEYW,:p_FILE_CRT_DATE,:p_FILE_VERSION,:p_FILE_SIZE,:p_DOWN_AMOUNT,:p_DEST_OBJ,:p_BIZ_OBJ,:p_SECRET_LVL,:p_LANG_TYPE,:p_FILE_TYPE,:p_SAVE_PATH,:p_USER_ID,:p_STATUS,:p_CREATE_TIME,:p_UPD_TIME,:p_FOLDER_ID,:p_TEAM_NAME,:p_FORM_UNIT,:p_SHARED_SCOPE_ID,:p_PDF_PATH,:p_SWF_PATH)";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "TEAM_ID", "FILE_NAME", "FILE_EXT", "FILE_ABST", "FILE_AUTHOR", "KEYW", "FILE_CRT_DATE", "FILE_VERSION", "FILE_SIZE", "DOWN_AMOUNT", "DEST_OBJ", "BIZ_OBJ", "SECRET_LVL", "LANG_TYPE", "FILE_TYPE", "SAVE_PATH", "USER_ID", "STATUS", "CREATE_TIME", "UPD_TIME", "FOLDER_ID", "TEAM_NAME", "FORM_UNIT", "SHARED_SCOPE_ID","PDF_PATH","SWF_PATH").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.TEAM_ID, model.FILE_NAME, model.FILE_EXT, model.FILE_ABST, model.FILE_AUTHOR, model.KEYW, model.FILE_CRT_DATE, model.FILE_VERSION, model.FILE_SIZE, model.DOWN_AMOUNT, model.DEST_OBJ, model.BIZ_OBJ, model.SECRET_LVL, model.LANG_TYPE, model.FILE_TYPE, model.SAVE_PATH, model.USER_ID, model.STATUS, model.CREATE_TIME, model.UPD_TIME, model.FOLDER_ID,model.TEAM_NAME,model.FORM_UNIT,model.SHARED_SCOPE_ID,model.PDF_PATH,model.SWF_PATH);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        public bool delete(decimal fileId)
        {
            bool result = true;
            if (fileId < 0)
            {
                return false;
            }

            string sql = @"delete from  TB_XMK_FILE  where FILE_ID=:p_FILE_ID ";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "FILE_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(fileId);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            return result;
        }

        public bool DeleteIN(string fileId)
        {
            bool result = true;


            string sql = @"delete from  TB_XMK_FILE  where FILE_ID in (" + fileId + ") ";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back < 1)
                result = false;
            return result;
        }

        /// <summary>
        /// 更新文件记录
        /// </summary>
        /// <param name="fileObj"></param>
        /// <returns></returns>
        public bool Update(TB_XMK_FILEInfo fileObj)
        {
            bool result = true;
            if (fileObj == null)
            {
                return false;
            }

            string sql = @"update TB_XMK_FILE  set USER_ID=:p_USER_ID, SAVE_PATH=:p_SAVE_PATH,CREATE_TIME=:p_CREATE_TIME ,UPD_TIME=:p_UPD_TIME ,  
                            FILE_NAME=:p_FILE_NAME, FILE_EXT=:p_FILE_EXT,  FILE_ABST=:p_FILE_ABST,  KEYW=:p_KEYW, FILE_CRT_DATE=:p_FILE_CRT_DATE, FILE_TYPE=:p_FILE_TYPE,FILE_AUTHOR=:p_FILE_AUTHOR,FILE_VERSION=:p_FILE_VERSION,DEST_OBJ=:p_DEST_OBJ,BIZ_OBJ=:p_BIZ_OBJ,SECRET_LVL=:p_SECRET_LVL,LANG_TYPE=:p_LANG_TYPE,TEAM_ID=:P_TEAM_ID,STATUS=:P_STATUS,
                            FOLDER_ID=:p_FOLDER_ID,TEAM_NAME=:p_TEAM_NAME,FORM_UNIT=:p_FORM_UNIT,SHARED_SCOPE_ID=:p_SHARED_SCOPE_ID  where FILE_ID=:p_FILE_ID";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "USER_ID", "SAVE_PATH", "CREATE_TIME", "UPD_TIME", "FILE_NAME", "FILE_EXT", "FILE_ABST", "KEYW", "FILE_CRT_DATE", "FILE_TYPE", "FILE_ID", "FILE_AUTHOR", "FILE_VERSION", "DEST_OBJ", "BIZ_OBJ", "SECRET_LVL", "LANG_TYPE", "TEAM_ID", "STATUS", "FOLDER_ID", "TEAM_NAME", "FORM_UNIT", "SHARED_SCOPE_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(fileObj.USER_ID, fileObj.SAVE_PATH, fileObj.CREATE_TIME, fileObj.UPD_TIME, fileObj.FILE_NAME, fileObj.FILE_EXT, fileObj.FILE_ABST, fileObj.KEYW, fileObj.FILE_CRT_DATE, fileObj.FILE_TYPE, fileObj.FILE_ID, fileObj.FILE_AUTHOR, fileObj.FILE_VERSION, fileObj.DEST_OBJ, fileObj.BIZ_OBJ, fileObj.SECRET_LVL, fileObj.LANG_TYPE, fileObj.TEAM_ID, fileObj.STATUS, fileObj.FOLDER_ID,fileObj.TEAM_NAME,fileObj.FORM_UNIT,fileObj.SHARED_SCOPE_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            return result;
        }


        /// <summary>
        /// 重新提交
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool NewAgainDataSubmitBySql(string File_ID)
        {
            string strSQL = @" UPDATE TB_XMK_FILE 
					SET STATUS = 0
					WHERE FILE_ID in(" + File_ID + ") ";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL);

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }


        /// <summary>
        /// 批量审核项目库文件
        /// </summary>
        /// <param name="fileObj"></param>
        /// <returns></returns>
        public bool UpdateDatasBySQL(string File_ID,string Folder_ID)
        {
            bool result = true;
            
            string sql = @"update TB_XMK_FILE  set FOLDER_ID=" + Folder_ID + " ,status=1 where FILE_ID in (" + File_ID + ")";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool AddBySql(TB_XMK_FILEInfo model)
        {
            string strSQL = @" INSERT INTO TB_XMK_FILE 
					(FILE_NAME,FILE_EXT,FILE_ABST,FILE_AUTHOR,KEYW,FILE_CRT_DATE,FILE_VERSION,FILE_SIZE，DOWN_AMOUNT，DEST_OBJ,BIZ_OBJ,SECRET_LVL,LANG_TYPE,FILE_TYPE,SAVE_PATH,USER_ID,TEAM_ID,STATUS,CREATE_TIME,UPD_TIME,PDF_PATH,SWF_PATH,TEAM_NAME,FORM_UNIT,SHARED_SCOPE_ID) 
					VALUES(:p_FILE_NAME,:p_FILE_EXT,:p_FILE_ABST,:p_FILE_AUTHOR,:p_KEYW,:p_FILE_CRT_DATE,:p_FILE_VERSION,:p_FILE_SIZE,:p_DOWN_AMOUNT,:p_DEST_OBJ,:p_BIZ_OBJ,:p_SECRET_LVL,:p_LANG_TYPE,:p_FILE_TYPE,:p_SAVE_PATH,:p_USER_ID,:p_TEAM_ID,:p_STATUS,:p_CREATE_TIME,:p_UPD_TIME,:p_PDF_PATH,:p_SWF_PATH,:p_TEAM_NAME,:p_FORM_UNIT,:p_SHARED_SCOPE_ID)";

            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "FILE_NAME", "FILE_EXT", "FILE_ABST", "FILE_AUTHOR", "KEYW", "FILE_CRT_DATE", "FILE_VERSION", "FILE_SIZE", "DOWN_AMOUNT", "DEST_OBJ", "BIZ_OBJ", "SECRET_LVL", "LANG_TYPE", "FILE_TYPE", "SAVE_PATH", "USER_ID", "TEAM_ID", "STATUS", "CREATE_TIME", "UPD_TIME", "PDF_PATH", "SWF_PATH", "TEAM_NAME", "FORM_UNIT", "SHARED_SCOPE_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.FILE_NAME, model.FILE_EXT, model.FILE_ABST, model.FILE_AUTHOR, model.KEYW, model.FILE_CRT_DATE, model.FILE_VERSION, model.FILE_SIZE, model.DOWN_AMOUNT, model.DEST_OBJ, model.BIZ_OBJ, model.SECRET_LVL, model.LANG_TYPE, model.FILE_TYPE, model.SAVE_PATH, model.USER_ID, model.TEAM_ID, model.STATUS, model.CREATE_TIME, model.UPD_TIME, model.PDF_PATH, model.SWF_PATH,model.TEAM_NAME,model.FORM_UNIT,model.SHARED_SCOPE_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="DestObjId">文件所在目标ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetModelByDestObjAndType(string op,string folder_id, int startNum, int endNum, ref int total)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  FOLDER_ID = '" + folder_id + "'and is_del=0");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);
            total = Convert.ToInt32(obj);


            StringBuilder strSql = new StringBuilder();
            if (op.Equals("FILE_SIZE"))
            {
                //strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "'  ) table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString() + " order by tokb(file_size) desc");
                strSql.Append("select * from(SELECT  ROWNUM AS rowno, FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT from (SELECT  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "'and is_del=0  and status!=0 order by tokb(file_size) desc))table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
            }
            else
            {
               // strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "'  ) table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString() + " order by " + op + " desc");
                strSql.Append("select * from(SELECT ROWNUM AS rowno,  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT  FROM (SELECT  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE,FILE_EXT  FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "' and is_del=0  and status!=0 order by " + op + " desc) )table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
            }
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="DestObjId">文件所在目标ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetModelByDestObjAndKeyWord(string folder_id,string keyword, int startNum, int endNum, ref int total)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  FOLDER_ID = '" + folder_id + "' and FILE_NAME like '%" + keyword + "%'");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);
            total = Convert.ToInt32(obj);


            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "' and is_del=0  and status!=0 and FILE_NAME like '%" + keyword + "%') table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString() + " order by Create_time desc");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="DestObjId">文件所在目标ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetModelByDestObj(string folder_id, int startNum, int endNum, ref int total)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  FOLDER_ID = '" + folder_id + "' ");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);
            total = Convert.ToInt32(obj);


            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,  FILE_NAME,FILE_ID,CREATE_TIME,UPD_TIME,DEST_OBJ,FILE_SIZE FROM TB_XMK_FILE WHERE FOLDER_ID = '" + folder_id + "' and is_del=0  and status!=0) table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString() + " order by Create_time desc");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="DestObjId">文件所在目标ID</param>
        /// <returns>文件列表</returns>
        public int GetCountByDestObjAndKeyWord(string folder_id,string keyword)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  FOLDER_ID = '" + folder_id + "' ");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);
            return Convert.ToInt32(obj);

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="DestObjId">文件所在目标ID</param>
        /// <returns>文件列表</returns>
        public int GetCountByDestObj(string folder_id)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  FOLDER_ID = '" + folder_id + "' ");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);
            return Convert.ToInt32(obj);

        }



        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetModelBySql(string FileID)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("select a.*,b.obj_name as bus_obj_name,c.obj_name as target_obj_name,d.team_name from TB_XMK_FILE a left join tb_tree_bus b on a.biz_obj = b.obj_id left join tb_tree_target c on a.dest_obj =c.obj_id left join tb_team d on a.team_id = d.team_id WHERE a.FILE_ID = ' " + FileID + "'");
            strSql.Append(" select a.*,d.team_name,c.user_name,s.team_name as xmk_name from TB_XMK_FILE a left join  tb_team d on a.team_id = d.team_id left join BASE_USERINFO c on a.user_id = c.user_id  LEFT JOIN tb_team s ON s.team_id=17 WHERE a.FILE_ID = ' " + FileID + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetxmkModelBySql(string FileID)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("select a.*,b.obj_name as bus_obj_name,c.obj_name as target_obj_name,d.team_name from TB_XMK_FILE a left join tb_tree_bus b on a.biz_obj = b.obj_id left join tb_tree_target c on a.dest_obj =c.obj_id left join tb_team d on a.team_id = d.team_id WHERE a.FILE_ID = ' " + FileID + "'");
            strSql.Append(" select a.*,d.team_name,c.user_name,s.team_name as xmk_name from TB_XMK_FILE a left join  tb_team d on a.team_id = d.team_id left join BASE_USERINFO c on a.user_id = c.user_id  LEFT JOIN tb_team s ON s.team_id=a.team_id WHERE a.FILE_ID in(" + FileID + ")");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public XMKFileExtInfo GetXMKFileExtInfoByID(string FileID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.*,d.team_name from TB_XMK_FILE a left join tb_team d on a.team_id = d.team_id WHERE a.FILE_ID = " + FileID);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            return DbManager.GetInfo(cmd,
                delegate(out XMKFileExtInfo model, DataRow row)
                {
                    model = new XMKFileExtInfo
                    {
                        FILE_ID = ParseHelper.Parse<long>(row["FILE_ID"]),
                        FILE_NAME = ParseHelper.Parse<string>(row["FILE_NAME"]),
                        FILE_EXT = ParseHelper.Parse<string>(row["FILE_EXT"]),
                        FILE_CRT_TIME = ParseHelper.Parse<DateTime>(row["FILE_CRT_DATE"]),
                        KEYW = ParseHelper.Parse<string>(row["KEYW"]),
                        UPD_TIME = ParseHelper.Parse<DateTime>(row["UPD_TIME"]),
                        FILE_TYPE = ParseHelper.Parse<string>(row["FILE_TYPE"]),
                        FILE_ABST = ParseHelper.Parse<string>(row["FILE_ABST"]),
                        CREATE_TIME = ParseHelper.Parse<DateTime>(row["CREATE_TIME"]),
                        SAVE_PATH = ParseHelper.Parse<string>(row["SAVE_PATH"]),
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        FILE_AUTHOR = ParseHelper.Parse<string>(row["FILE_AUTHOR"]),
                        FILE_VERSION = ParseHelper.Parse<string>(row["FILE_VERSION"]),
                        FILE_SIZE = ParseHelper.Parse<string>(row["FILE_SIZE"]),
                        DOWN_AMOUNT = ParseHelper.Parse<decimal>(row["DOWN_AMOUNT"]),
                        DEST_OBJ = ParseHelper.Parse<string>(row["DEST_OBJ"]),
                        BIZ_OBJ = ParseHelper.Parse<string>(row["BIZ_OBJ"]),
                        SECRET_LVL = ParseHelper.Parse<string>(row["SECRET_LVL"]),
                        LANG_TYPE = ParseHelper.Parse<string>(row["LANG_TYPE"]),
                        BIZ_OBJ_NAME = ParseHelper.Parse<string>(row["biz_obj"]),
                        DEST_OBJ_NAME = ParseHelper.Parse<string>(row["dest_obj"]),
                        TEAM_ID = ParseHelper.Parse<int>(row["TEAM_ID"]),
                        TEAM_NAME = ParseHelper.Parse<string>(row["TEAM_NAME"]),
                        PDFFilePath = ParseHelper.Parse<string>(row["PDF_PATH"]),
                        SwfFilePath = ParseHelper.Parse<string>(row["SWF_PATH"]),
                        PRE_PIC = ParseHelper.Parse<string>(row["PRE_PIC"])
                    };
                });
        }

        /// <summary>
        /// 获取未审核文件
        /// </summary>
        /// <returns>文件列表</returns>
        public DataTable GetUnauditedModelBySql(string Team_ID, string sorttype, string sortdesc, string status, int startNum, int endNum, ref int total)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where  team_id='" + Team_ID + "' and status=" + status);
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);

            total = Convert.ToInt32(obj);

            StringBuilder strSql = new StringBuilder();
            if (sorttype == "time")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,file_id,file_name,CREATE_TIME from(SELECT a.file_id,a.file_name,a.CREATE_TIME FROM TB_XMK_FILE a where team_id='" + Team_ID + "' and status=" + status + " order by a.CREATE_TIME desc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
                else
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno,file_id,file_name,CREATE_TIME from(SELECT a.file_id,a.file_name,a.CREATE_TIME FROM TB_XMK_FILE a where team_id='" + Team_ID + "' and status=" + status + " order by a.CREATE_TIME asc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
            }
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 获取未审核文件 By CaoBin 20140504
        /// </summary>
        /// <returns>文件列表</returns>
        public DataTable GetXMKUnauditedModelBySql(int startNum, string sorttype, string sortdesc, int endNum, ref int total)
        {
            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE  where status = 0");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);

            total = Convert.ToInt32(obj);

            StringBuilder strSql = new StringBuilder();
            if (sorttype == "time")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from (SELECT TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =0 order by TB_XMK_FILE.CREATE_TIME desc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
                else
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from(SELECT TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =0 order by TB_XMK_FILE.CREATE_TIME asc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
            }
            else if (sorttype == "user")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from(SELECT TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =0 order by TB_XMK_FILE.USER_ID desc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
                else
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from(SELECT TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =0 order by TB_XMK_FILE.USER_ID asc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
            }
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 获取已审核文件 By CaoBin 20140504
        /// </summary>
        /// <returns>文件列表</returns>
        public DataTable GetXMKAuditModelBySql(int startNum, string sorttype, string sortdesc, int endNum, ref int total)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE  where status = 1");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);

            total = Convert.ToInt32(obj);


            StringBuilder strSql = new StringBuilder();
            if (sorttype == "time")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from (SELECT  ROWNUM AS rowno, TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =1 order by TB_XMK_FILE.CREATE_TIME desc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
                else
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from (SELECT  ROWNUM AS rowno, TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =1 order by TB_XMK_FILE.CREATE_TIME asc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
            }
            else if (sorttype == "user")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from (SELECT  ROWNUM AS rowno, TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =1 order by TB_XMK_FILE.USER_ID desc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
                else
                {
                    strSql.Append("SELECT * FROM (SELECT  ROWNUM AS rowno, FILE_ID,FILE_NAME,USER_ID,USER_NAME,CREATE_TIME,UPD_TIME，SAVE_PATH from (SELECT  ROWNUM AS rowno, TB_XMK_FILE.FILE_ID,TB_XMK_FILE.FILE_NAME,TB_XMK_FILE.USER_ID,TB_XMK_FILE.CREATE_TIME,TB_XMK_FILE.UPD_TIME，TB_XMK_FILE.SAVE_PATH,base_userinfo.user_name from TB_XMK_FILE,base_userinfo where TB_XMK_FILE.user_id = base_userinfo.user_id and TB_XMK_FILE.status =1 order by TB_XMK_FILE.USER_ID asc)) table_tmp WHERE table_tmp.rowno >  " + startNum.ToString() + "  and table_tmp.rowno <" + endNum.ToString() + "");
                }
            }
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 退回数据By CaoBin 20140504
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool BackFileBySql(string SINGLERECEIPT, string FILE_ID)
        {
            string strSQL = @" UPDATE TB_XMK_FILE 
					SET SINGLERECEIPT = '" + SINGLERECEIPT + "',Status=2 WHERE FILE_ID in (" + FILE_ID + ") ";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 审核数据
        /// </summary>
        /// <param name="FileID">文件编号</param>
        /// <returns>成功返回true，失败返回false</returns>
        public bool AuditDataBySql(string FileID)
        {
            string strSQL = @" update TB_XMK_FILE set STATUS=1,folder_id=0 where File_ID=" + FileID;

            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;
        }

        /// <summary>
        /// 根据文件名称、文件路径
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable getXmkFileyFileNameAndPath(string FileName, string Path)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from TB_XMK_FILE  WHERE FILE_NAME='" + FileName + "' AND FILE_ID='" + Path + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 根据文件名称、文件路径获得当前课题组文件
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable getTeamFileyFileNameAndPath(string FileName, string Path)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.*,b.obj_name as bus_obj_name,c.obj_name as target_obj_name,a.file_size from TB_XMK_FILE a left join tb_tree_bus b on a.biz_obj = b.obj_id left join tb_tree_target c on a.dest_obj =c.obj_id  WHERE a.FILE_NAME='" + FileName + "' AND a.SAVE_PATH='" + Path + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable QueryById(string fileId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from tb_xmk_file  WHERE FILE_ID=" + fileId);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 修改源数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool UpDateSourceDataBySql(TB_XMK_FILEInfo model)
        {
            string strSQL = @" UPDATE TB_XMK_FILE 
					SET FILE_NAME = :p_FILE_NAME,FILE_AUTHOR = :p_FILE_AUTHOR,KEYW = :p_KEYW,FILE_CRT_DATE = :p_FILE_CRT_DATE,DEST_OBJ = :p_DEST_OBJ,BIZ_OBJ = :p_BIZ_OBJ,FILE_ABST=:p_FILE_ABST,FILE_EXT=:p_FILE_EXT,LANG_TYPE=:p_LANG_TYPE,FILE_VERSION=:p_FILE_VERSION,SECRET_LVL=:p_SECRET_LVL,SHARED_SCOPE_ID=:p_SHARED_SCOPE_ID
					WHERE FILE_ID=:p_FILE_ID ";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "FILE_ID", "FILE_NAME", "FILE_AUTHOR", "KEYW", "FILE_CRT_DATE", "DEST_OBJ", "BIZ_OBJ", "FILE_ABST", "FILE_EXT", "LANG_TYPE", "FILE_VERSION", "SECRET_LVL", "SHARED_SCOPE_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.FILE_ID, model.FILE_NAME, model.FILE_AUTHOR, model.KEYW, model.FILE_CRT_DATE, model.DEST_OBJ, model.BIZ_OBJ, model.FILE_ABST, model.FILE_EXT, model.LANG_TYPE, model.FILE_VERSION, model.SECRET_LVL, model.SHARED_SCOPE_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 重新提交
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool AgainDataSubmitBySql(TB_XMK_FILEInfo model, string Flag)
        {
            string strSQL = @" UPDATE TB_XMK_FILE 
					SET FILE_NAME = :p_FILE_NAME,FILE_AUTHOR = :p_FILE_AUTHOR,KEYW = :p_KEYW,FILE_CRT_DATE = :p_FILE_CRT_DATE,DEST_OBJ = :p_DEST_OBJ,BIZ_OBJ = :p_BIZ_OBJ,STATUS = :p_STATUS
					WHERE FILE_ID=:p_FILE_ID ";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "FILE_ID", "FILE_NAME", "FILE_AUTHOR", "KEYW", "FILE_CRT_DATE", "DEST_OBJ", "BIZ_OBJ", "STATUS").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.FILE_ID, model.FILE_NAME, model.FILE_AUTHOR, model.KEYW, model.FILE_CRT_DATE, model.DEST_OBJ, model.BIZ_OBJ, model.STATUS);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 修改关键词和摘要信息
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool UpDateInfoBySql(TB_XMK_FILEInfo model, string types)
        {
            bool result = true;
            string strSQL = "";
            if (types.Equals("ZYXX"))
            {
                strSQL = @" UPDATE TB_XMK_FILE 
					set FILE_ABST=:p_FILE_ABST
					WHERE FILE_ID=:p_FILE_ID ";


                //新建一个数据库操作帮助类
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                    //参数生成
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "FILE_ID", "FILE_ABST").ToArray();
                    });
                //参数设值
                cmd.SetParamValues(model.FILE_ID, model.FILE_ABST);
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                int back = DbManager.ExecNonQuery(cmd);
                if (back == 0)
                    result = false;


            }
            else if (types.Equals("GJC"))
            {
                strSQL = @" UPDATE TB_XMK_FILE 
					set KEYW = :p_KEYW
					WHERE FILE_ID=:p_FILE_ID ";


                //新建一个数据库操作帮助类
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                    //参数生成
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "FILE_ID", "KEYW").ToArray();
                    });
                //参数设值
                cmd.SetParamValues(model.FILE_ID, model.KEYW);
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                int back = DbManager.ExecNonQuery(cmd);
                if (back == 0)
                    result = false;


            }
            return result;

        }

        //根据文件ID将文件移动到回收站
        public bool RemoveToRecycleBySql(string File_ID)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update TB_XMK_FILE set is_del=1,RECYCLE_DATE=to_date('" + System.DateTime.Now.Date.ToString("yyyy-MM-dd") + "','yyyy-MM-dd') where file_id in (" + File_ID + ")");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                return DbManager.ExecNonQuery(cmd) > 0;

            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return false;
        }
        /// <summary>
        /// 上传不可转换文件预览图片
        /// </summary>
        /// <param name="FileID"></param>
        /// <returns></returns>
        public bool PrePicAdd(PrePicCond cond)
        {
            try
            { 
                StringBuilder strSql = new StringBuilder();
                if (cond.SPACE == "20")
                {
                    strSql.Append("update TB_TEAM_FILE set PRE_PIC='" + cond.PRE_PIC + "' WHERE FILE_ID='" + cond.FILE_ID + "'");
                }
                if (cond.SPACE == "30")
                {
                    strSql.Append("update TB_XMK_FILE set PRE_PIC='" + cond.PRE_PIC + "' WHERE FILE_ID='" + cond.FILE_ID + "'");
                }
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                return DbManager.ExecNonQuery(cmd) > 0;

            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return false;
        }
        #region 项目库文件夹管理

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetTree_XmkBySql(string OBJ_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.*, t.rowid from tb_tree_xmk t where obj_id=" + OBJ_ID + "");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取子文件夹文件列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>文件列表</returns>
        public DataTable GetSTree_XmkBySql(string OBJ_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select t.*, t.rowid from tb_tree_xmk t where P_OBJ_ID=" + OBJ_ID + "");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 项目库文件夹修改名称
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool UpdateTree_XmkBySql(TB_Tree_ObjectInfo model)
        {
            string strSQL = @" UPDATE TB_TREE_XMK 
		SET OBJ_NAME = :p_OBJ_NAME where OBJ_ID=:p_OBJ_ID";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "OBJ_ID", "OBJ_NAME").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.ObjectID, model.ObjectName);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 项目库文件夹剪切
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool UpdateTree_XmkCUTBySql(TB_Tree_ObjectInfo model)
        {
            string strSQL = @" UPDATE TB_TREE_XMK 
		 set P_OBJ_ID = :p_P_OBJ_ID where OBJ_ID=:p_OBJ_ID";
            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSQL,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "OBJ_ID", "P_OBJ_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.ObjectID, model.PObjectID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 根据文件名称、文件路径
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable getXmkFileByFOLDER_ID(string FOLDER_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from TB_XMK_FILE  WHERE FOLDER_ID='" + FOLDER_ID + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        //删除文件夹
        public bool deleteTREE_XMK(string OBJ_ID)
        {
            bool result = true;
            
            string sql = @"delete from  TB_TREE_XMK  where OBJ_ID=:p_OBJ_ID ";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "OBJ_ID").ToArray();
                });
            //参数设值
            cmd.SetParamValues(OBJ_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            return result;
        }


        #endregion 项目库文件夹管理


        /// <summary>
        /// 获取回收站信息
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <returns>结果集</returns>
        public DataTable GetRecycleDataBySql(int startNum, string sorttype, string sortdesc, int endNum, ref int total)
        {
            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT count(*) FROM TB_XMK_FILE where is_del=1");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd_);

            total = Convert.ToInt32(obj);
            StringBuilder strSql = new StringBuilder();
            if (sorttype == "time")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append(@"select * from(SELECT  ROWNUM AS rowno,file_id,file_name,FILE_SIZE,RECYCLE_DATE from (select file_id,file_name,FILE_SIZE,RECYCLE_DATE from tb_xmk_file where is_del=1 order by Create_time desc) )table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
                }
                else
                {
                    strSql.Append(@"select * from(SELECT  ROWNUM AS rowno,file_id,file_name,FILE_SIZE,RECYCLE_DATE from (select file_id,file_name,FILE_SIZE,RECYCLE_DATE from tb_xmk_file where is_del=1 order by Create_time asc) )table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
                }
            }
            else if (sorttype == "size")
            {
                if (sortdesc == "desc")
                {
                    strSql.Append(@"select * from(SELECT  ROWNUM AS rowno,file_id,file_name,FILE_SIZE,RECYCLE_DATE from (select file_id,file_name,FILE_SIZE,RECYCLE_DATE from tb_xmk_file where is_del=1 order by tokb(FILE_SIZE） desc) )table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
                }
                else
                {
                    strSql.Append(@"select * from(SELECT  ROWNUM AS rowno,file_id,file_name,FILE_SIZE,RECYCLE_DATE from (select file_id,file_name,FILE_SIZE,RECYCLE_DATE from tb_xmk_file where is_del=1 order by tokb(FILE_SIZE）asc) )table_tmp WHERE table_tmp.rowno > " + startNum.ToString() + " and table_tmp.rowno <" + endNum.ToString());
                }
            }
            
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="FileID">文件IDs</param>
        /// <returns>文件列表</returns>
        public DataTable GetModelListBySql(string FileID)
        {
            StringBuilder strSql = new StringBuilder();
            
            strSql.Append(" select * from TB_XMK_FILE WHERE FILE_ID in(" + FileID + ")");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }


        //根据文件ID将文件从回收站移回空间
        public bool RecycleToSpaceBySql(string File_ID)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update TB_XMK_FILE set is_del=0 where file_id in ("+File_ID+")");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                return DbManager.ExecNonQuery(cmd) > 0;

            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return false;
        }
        //获取项目库空间同名文件最大版本号
        public decimal GetMaxFileVersionXmk(string fileName)
        {

            try
            {

                //获得待审核文件信息
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select max(FILE_VERSION) FROM TB_XMK_FILE where FILE_NAME='" + fileName + "'");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

                cmd.DbCmdInfo.CommandType = CommandType.Text;
                DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
                if (ds != null)
                {
                    return ParseHelper.Parse<decimal>(ds.Rows[0][0]);
                }

            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return 0;
        }
        /// <summary>
        /// 获取工区文件列表
        /// </summary>
        /// <param name="gqName">工区名称</param>
        /// <returns>获取工区文件列表</returns>
        public DataTable GetGQFiles(string gqName)
        {

            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT FILE_ID，FILE_NAME，FILE_EXT，FILE_SIZE，UPD_TIME，KEYW，FILE_ABST FROM TB_XMK_FILE where (Lower(FILE_EXT)='segy' or Lower(FILE_EXT)='sgy') and DEST_OBJ = '" + gqName + "' ");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd_.DbProvider, cmd_.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        /// <summary>
        /// 获取项目库空间所有文件
        /// </summary>
        /// <returns></returns>
        public DataTable getXmkFileIdAndObj()
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select FILE_ID,DEST_OBJ,BIZ_OBJ from TB_XMK_FILE ");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

         /// <summary>
        /// 分类查看查询数据
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable getXmkClassFlie(string FOLDER_ID, string classType)
        {
            StringBuilder strSql = new StringBuilder();
            if (classType == "CREATE_TIME")
            {
                strSql.Append("select FILE_ID,FILE_NAME," + classType + " from TB_XMK_FILE  WHERE FOLDER_ID='" + FOLDER_ID + "'order by " + classType + "");
            }
            else
            {
                strSql.Append("select FILE_ID,FILE_NAME,CREATE_TIME," + classType + " from TB_XMK_FILE  WHERE FOLDER_ID='" + FOLDER_ID + "'order by " + classType + "");
            }
           

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 分类查看明细数据
        /// </summary>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public DataTable getXmkClassDetailFile(string FOLDER_ID, string sqlwhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID as id,FILE_NAME,fILE_SIZE,CREATE_TIME,SAVE_PATH from TB_XMK_FILE  WHERE "+sqlwhere);
  
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        /// <summary>
        /// 获?取¨?录?井?文?件t列¢D表À¨ª
        /// </summary>
        /// <param name="wellName">井?名?称?</param>
        /// <returns>获?取¨?录?井?文?件t列¢D表À¨ª</returns>
        public DataTable GetLoggingFiles(string wellName)
        {
            StringBuilder strSql_ = new StringBuilder();
            strSql_.Append("SELECT FILE_ID，ê?FILE_NAME，ê?FILE_EXT，ê?FILE_SIZE，ê?UPD_TIME，ê?KEYW，ê?FILE_ABST FROM TB_XMK_FILE where (Lower(FILE_EXT)='las') and DEST_OBJ = '" + wellName + "' ");
            // strSql_.Append("SELECT FILE_ID，ê?FILE_NAME，ê?FILE_EXT，ê?FILE_SIZE，ê?UPD_TIME，ê?KEYW，ê?FILE_ABST FROM TB_XMK_FILE where (LOWER(substr(file_name,LENGTH(file_name)-3))='.las') and DEST_OBJ = '" + wellName + "' ");
            DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, strSql_.ToString());
            cmd_.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd_.DbProvider, cmd_.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }

        #endregion  成员方法
    }
}
